﻿//                       NOTICE
// 
// This software was produced for the U. S. Government
// under Contract No. FA8721-10-C-0001, and is
// subject to the Rights in Noncommercial Computer Software
// and Noncommercial Computer Software Documentation Clause
// (DFARS) 252.227-7014 (JUN 1995)
// 
// � 2010 The MITRE Corporation. All Rights Reserved. 

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Surface.Core;
using Microsoft.Xna.Framework;

namespace MXSE.MultiTouch.Gestures
{
    public class SlideGesture : BasicGesture
    {
        //Stores the last significant change to the position.
        //Used to determine the direction the slide is moving in.
        public Vector2 lastChange;

        //Used for messaging - better than creating a new message during each update loop
        

        /// <summary>
        /// Constructor, uses an old TouchGesture to make a new SlideGesture.
        /// </summary>
        /// <param name="touchGesture">Old TouchGesture that will become a SlideGesture</param>
        public SlideGesture(TouchGesture touchGesture)
        {
            startPosition = touchGesture.startPosition;
            startTime = touchGesture.startTime;
            currentPosition = touchGesture.currentPosition;
            lastPosition = touchGesture.currentPosition;
            Id = touchGesture.Id;
        }

        public override void Update()
        {
            if (Math.Abs(lastPosition.X - currentPosition.X) > 3
                || Math.Abs(lastPosition.Y - currentPosition.Y) > 3)
                lastChange = lastPosition;

            base.Update();
        }

        protected override void OnDeath()
        {
            if (message != null)
            {
                message.Destroy();
            }
        }
    }
}
